home *** CD-ROM | disk | FTP | other *** search
- Path: surfnet.nl!sun4nl!ittpub!ittpub!nntp
- Newsgroups: comp.lang.c++
- Subject: Re: Operator overloading
- Message-ID: <1996Mar8.163132.1795@ittpub>
- From: wil@ittpub.nl (Wil Evers)
- Date: 8 Mar 96 16:31:32 WET
- References: <313F19B5.41C6@lfa.uni-wuppertal.de>
- Distribution: world
- Nntp-Posting-Host: lintilla
-
- In article <313F19B5.41C6@lfa.uni-wuppertal.de> Oliver Heinz
- <heinz@lfa.uni-wuppertal.de> writes:
-
- > Hello out there,
- >
- > can somebody explain to me this strange looking operator overloading:
- >
- > const T& operator[](unsigned long int index) const;
- >
- > I know, it is an subscription overloading, for something like
- > v[i], where i is of type unsigned long int and v of type T.
- >
- > What's the meaning of the const at the end
- > and the beginning of the line ?
- >
- > Any help is greatly appreciated, thanks in advance ...
- >
- > Oliver
-
- Before answering your question -: I'm always amazed at the amount of
- questions in this newsgroup that clearly indicate someone is programming
- in C++ without reading a decent introductory book about it first. Please
- believe me: C++ is just too darn complex to simply bang away in it, even
- if you're a C expert... Sooner or later, the language will come back to
- hunt you.
-
- To answer your question: the first `const' means you cannot modify the
- object that the returned reference is referring to. The second `const'
- means this member function does not change the object it is called on, so
- it can be called on objects which are declared as constant. This
- combination makes perfect sense, because this member function is probably
- returning a reference to something that is - at least logically - stored
- in the object you call it on.
-
- - Wil
-